<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Article extends CI_Controller {
	public $catalogs;
	public function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('catalog_model');
		$this->load->model('article_model');
		$this->catalogs=$this->catalog_model->getall();
	}
	public function index($page=1){
        $this->load->model('Article_model');
        $total = $this->Article_model->count_all();
		$page_size = 10;
		$articles=$this->article_model->get_by_page($page,$page_size);
		$data = array(
			"catalogs" =>$this->catalogs,
			"articles" =>$articles,
			"catalog_id"=>0
		);
        $config['use_page_numbers'] = TRUE;    
        $this->load->library('pagination');
        $config['base_url'] = site_url('/article/index/');
        $config['total_rows'] = $total;
        $config['per_page'] = $page_size; 

        $this->pagination->initialize($config);
        $this->load->view('Article_index',$data);
	}
	public function view($id){
		$this->output->enable_profiler(TRUE);
		$article=$this->article_model->get_one($id);
		$this->article_model->view_once($id);
		$data = array(
			"catalogs" =>$this->catalogs,
			"article" =>$article,
			"catalog_id"=>$article->catalog_id
		);
		$this->load->view('article_view',$data);
	}
	public function lists($cata_id){
		$articles=$this->article_model->get_by_cata_id($cata_id);
		$data = array(
			"catalogs" =>$this->catalogs,
			"articles" =>$articles,
			"catalog_id"=>$cata_id
		);
		$this->load->view('article_index',$data);
	}
}
